package com.hr.rbac.service.Impl;

import java.util.List;

import org.junit.Test;

import com.hr.rbac.dao.Impl.FunctionDaoImpl;
import com.hr.rbac.dao.Impl.PrivilegeDaoImpl;
import com.hr.rbac.dao.Impl.RoleDaoImpl;
import com.hr.rbac.domain.Function;
import com.hr.rbac.domain.Privilege;
import com.hr.rbac.domain.Role;
import com.hr.rbac.service.RoleService;
import com.hr.utils.PageBean;

public class RoleServiceImpl implements RoleService {
	private RoleDaoImpl roleDaoImpl = new RoleDaoImpl();
	private PrivilegeDaoImpl privilegeDaoImpl = new PrivilegeDaoImpl();
	private FunctionDaoImpl functionDaoImpl = new FunctionDaoImpl();
	@Override
	public Role findRoleByUserID(String userID) {
		return roleDaoImpl.findByRoleUserId(userID);
	}
	
	@Override
	public PageBean<Role> queryAll_Page(int PageCurrent, int PageSize) {
		
		PageBean<Role> pageBean = roleDaoImpl.queryAll_Page(PageCurrent, PageSize);
		List<Role> list_role = pageBean.getBeanList();
		for(int i = 0;i < list_role.size();i++) {
			List<Privilege> privileges = privilegeDaoImpl.findByRoleId(list_role.get(i).getRole_ID());
			for(int j = 0;j <privileges.size();j++) {
				List<Function> functions = functionDaoImpl.findByPrivilegeID(privileges.get(j));
				privileges.get(j).setFunctions(functions);
			}
			list_role.get(i).setPrivileges(privileges);
		}
		pageBean.setBeanList(list_role);
		return pageBean;
	}

	@Override
	public void saveRole(String privilege_id, String function_id,String role_id) {
		roleDaoImpl.saveRole(privilege_id,function_id,role_id);
	}
	
	@Override
	public void saveRole_Privilege(String privilege_Id, String role_ID) {
		// TODO Auto-generated method stub
		roleDaoImpl.saveRole_Privilege(privilege_Id, role_ID);
	}
	
	@Override
	public void save(Role role) {
		// TODO Auto-generated method stub
		roleDaoImpl.save(role);
	}
	
	@Override
	public List<Role> queryAllRole() {
		// TODO Auto-generated method stub
		return roleDaoImpl.QueryAll();
	}
	
	@Override
	public void saveRoleAndUser(String user_id, String role_id) {
		// TODO Auto-generated method stub
		roleDaoImpl.saveRoleAndUser(user_id,role_id);
	}
	
	@Override
	public void updateRoleAndUser(String user_id, String role_id) {
		// TODO Auto-generated method stub
		roleDaoImpl.updateRoleAndUser(user_id,role_id);
	}
	
	@Override
	public Role findRoleByRoleID(String role_ID) {
		// TODO Auto-generated method stub
		return roleDaoImpl.findByRoleId(role_ID);
	}
	
	@Override
	public void deleteRoleByRoleID(String role_id) {
		// TODO Auto-generated method stub
		roleDaoImpl.deleteRoleByRoleID(role_id);
	}
	
	@Override
	public void updateRoleByRoleID(String role_id) {
		// TODO Auto-generated method stub
		roleDaoImpl.updateRoleByRoleID(role_id);
	}
	

}
